package com.oro.validator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class EmailValidator implements Validator {

	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {

		String enteredName = (String) value;

		Pattern p = Pattern.compile(".+@.+\\.[a-z]+");

		Matcher m = p.matcher(enteredName);

		if (!m.matches()) {
			FacesMessage message = new FacesMessage();
			message.setSummary("Indirizzo email non valido.");
			throw new ValidatorException(message);
		}

	}
}
